//
//  BGGetAddListDataModel.m
//  bigMall
//
//  Created by LTOVE on 16/8/10.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGGetAddListDataModel.h"
#import "BGGoodInfoResult.h"

#import "BGAddListTitleModel.h"
#import "BGAddListTextFildViewModel.h"
#import "BGAddlistWithaccessoryViewModel.h"

#import "BGGoodAttrsModel.h"

#import "BGGoodInfoResult.h"

@implementation BGGetAddListDataModel

+ (NSArray *)getDataArrayWithBGGoodInfoResult:(BGGoodInfoResult *)result
{
    BGGetAddListDataModel *MM = [[BGGetAddListDataModel alloc]init];
    NSMutableArray *dataArray = [NSMutableArray array];
    //标题
    BGAddListTitleModel *titleModel = [[BGAddListTitleModel alloc]init];
    titleModel.title = [MM titleStrWith:result];
    [dataArray addObject:titleModel];
    //textFild
    NSString *titleStr = [NSString stringWithFormat:@"采购数量(%@):",result.unit];
    NSString *textFild = [NSString stringWithFormat:@"至少采购%@%@以上",result.least_number,result.unit];
    BGAddListTextFildViewModel *textFildModel = [[BGAddListTextFildViewModel alloc]init];
    textFildModel.title = titleStr;
    textFildModel.textFildStr = textFild;
    [dataArray addObject:textFildModel];
    //access  使用循环添加
    [MM addObjectToDataArrayWithDataArray:dataArray andarray:result.goods_attrs];
    //单价
    BGAddListTitleModel *priceModel = [[BGAddListTitleModel alloc]init];
    BGAddListTitleModel *totPriceModel = [[BGAddListTitleModel alloc]init];
    priceModel.title = [NSString stringWithFormat:@"单价: %@元",result.price];
    totPriceModel.title = @"总金额:";
    [dataArray addObject:priceModel];
    [dataArray addObject:totPriceModel];
    
    
    return dataArray;
}
#pragma mark - 解析参数数据20161216
- (void)addObjectToDataArrayWithDataArray:(NSMutableArray *)dataArray andarray:(NSArray *)array
{
    NSMutableArray *MutableArray = [NSMutableArray array];
    for (BGGoodAttrsModel *model in array) {
        if ([model.attr_type isEqualToString:@"3"] || [model.attr_type isEqualToString:@"5"]) {
            BGAddlistWithaccessoryViewModel *dataModel = [[BGAddlistWithaccessoryViewModel alloc]init];
            dataModel.title = [NSString stringWithFormat:@"%@:",model.name];
            dataModel.is_default = model.is_default;
            dataModel.attr_type = model.attr_type;
            NSMutableArray *array = [NSMutableArray array];
            for (int i = 0 ; i < model.default_value.count; i++) {
                [array addObject:[NSString stringWithFormat:@"%@    浮动值:%@",model.default_value[i],model.change_price[i]]];
            }
            for (int i = 0; i < model.is_default.count; i++) {
                NSString *str = model.is_default[i];
                if ([str isEqualToString:@"true"] ) {
                    dataModel.defaultStr = model.default_value[i];
                    dataModel.title = [NSString stringWithFormat:@"%@:%@    浮动值:%@",model.name, model.default_value[i],model.change_price[i]];
                }
            }
            dataModel.dataArray =@[ array];
            dataModel.isDatePick = NO;
            dataModel.idStr = model.idStr;
            NSLog(@"%@",dataModel.idStr);
            [dataArray addObject:dataModel];
        }else if ([model.attr_type isEqualToString:@"4"]){
        
#pragma mark --
            BGShopAddListBasicModelType4 *dataModel = [BGShopAddListBasicModelType4 new];
            dataModel.title = [NSString stringWithFormat:@"%@:",model.name];
            dataModel.is_default = model.is_default;
            
            dataModel.attr_type = model.attr_type;
            dataModel.idStr = model.idStr;
            NSMutableArray *array = [NSMutableArray array];
            for (int i = 0 ; i < model.default_value.count; i++) {
                [array addObject:[NSString stringWithFormat:@"%@    浮动值:%@",model.default_value[i],model.change_price[i]]];
            }
            dataModel.dataArray = array;
//            [dataArray addObject:dataModel];
            [MutableArray addObject:dataModel];
        }
    }
   
    BGAddlistWithaccessoryViewModel *timeModel = [[BGAddlistWithaccessoryViewModel alloc]init];
    timeModel.title = @"提货时间:";
    timeModel.isDatePick = YES;
#pragma mark -
#pragma mark - 打开提货时间 打开下边一行注释
//    [dataArray addObject:timeModel];
    [dataArray addObjectsFromArray:MutableArray];
}

/**
 *  拼接title
 *
 *  @param result result description
 *
 *  @return return value description
 */
- (NSString *)titleStrWith:(BGGoodInfoResult *)result
{
    //总库存
    NSString *orignNumber = result.origin_number;
    //现在库存
    NSString *number = result.number;
    //计量单位
    NSString *unit = result.unit;
    //拼接
    return [NSString stringWithFormat:@"总库存%@%@,剩余库存%@%@",orignNumber,unit,number,unit];
    
}

@end
